class LogoScene extends eui.Component implements  eui.UIComponent {

	public btnStart:eui.Image;
	public btnSound:eui.ToggleButton;	

	public constructor() {
		super();
		
	}

	protected partAdded(partName:string,instance:any):void
	{
		super.partAdded(partName,instance);
	}


	protected childrenCreated():void
	{
		super.childrenCreated();
		
		this.btnStart.touchEnabled = true;				
		Global.globalVar.instance.bg_sound = RES.getRes("music_main_mp3");		
		Global.globalVar.instance.bg_channel = Global.globalVar.instance.bg_sound.play(Global.globalVar.instance.bg_pauseTime, 1);
		// 事件委托, 点击按钮的时候触发
		this.btnStart.addEventListener(egret.TouchEvent.TOUCH_TAP, this.GoLevel, this);
		this.btnSound.addEventListener(egret.Event.CHANGE,this.IsPlayMusic,this);		
		this.btnSound.addEventListener(egret.TouchEvent.TOUCH_TAP,this.PlayMusic,this);
		
	}

	/**
	 * start按钮
	 */
	public GoLevel() {		
		//事件驱动方式
		Custom.SceneMngDispatcher.ins.dispatchEvent(new Custom.SceneMngEvent(Custom.SceneMngEvent.LEVEL, 1));
		//场景管理方式
		//SceneMng.toLevelScene();
	}

	/**
	 * sound按钮
	 */
	public IsPlayMusic(e:egret.Event) {		
		if(this.btnSound.selected){							
			Global.globalVar.instance.IsSound = false;	
			//console.log(Global.globalVar.instance.IsSound);		
		}
		else{						
			Global.globalVar.instance.IsSound = true;			
			//console.log(Global.globalVar.instance.IsSound);					
		}  		
	}

	public PlayMusic() {
		if(Global.globalVar.instance.IsSound) {
			Global.globalVar.instance.bg_channel = Global.globalVar.instance.bg_sound.play(Global.globalVar.instance.bg_pauseTime, 0);
		}
		else{
			if (Global.globalVar.instance.bg_channel) {
				Global.globalVar.instance.bg_pauseTime = Global.globalVar.instance.bg_channel.position;
				Global.globalVar.instance.bg_channel.stop();
				Global.globalVar.instance.bg_channel = null;
			}
		}
	}
	
}